<?php if ($section == "proposal_titles") echo "<h3>Project Deliverable(s) in this Module</h3>"; else echo "<a name='map'></a><h2>Course Project Map</h2>"; ?>
<?php if ($modal_window != "true") { ?><p><span class="icon"><img src="images/page_add.png" border="0" align="absmiddle" /></span><a id="modal_window_link" href="index.php?section=proj_deliv&action=add&go=<?php if (strstr($section, "step"))  echo "confirm"; else echo "default"; ?>&cid=<?php echo $cid; ?>&amp;modal_window=true">Add a Project Deliverable</a><?php } ?>
<?php
if ($section != "proposal_titles") {
do { $c[] = $row_pd['mid']; } while($row_pd = mysql_fetch_assoc($pd));
sort($c);
echo "
<table class='dataTable'>
  <tr>
    <th width='15%' nowrap='nowrap'>Applies To</th>
    <th>Course Project Deliverable</th>";
	if ((!strstr($section, "step")) && ($modal_window != "true")) { 
	echo "
	<th width='13%' nowrap='nowrap'>Associated<br>CLOs?</th>
	<th width='13%' nowrap='nowrap'>ID / Reveiwer<br>Comments?</th>
	<th width='13%' nowrap='nowrap'>Changes<br>Needed?</th>";
	}
	if ($section == "proposal_reveiw") echo "<th width='13%' nowrap='nowrap'>Make Changes?</th>";
	if ($row_user['userLevel'] <= "2"){
		if ($section == "view_proposal") {
    echo "
	<th width='13%' nowrap='nowrap'>Latest Version</th>
    <th width='13%'>Other Versions</th>
	";
		}
	}
	echo "</tr>";
	
		foreach (array_unique($c) as $value) {
				// Was NOT returning the first row for some reason - found out that you MUST use the do...while loop to build the arrays.
				$query_pd_num = sprintf("SELECT * FROM project_deliverable WHERE cid='%s' AND mid='%s' ORDER BY mid,del_num,vid ASC", $cid, $value);
				$pd_num = mysql_query($query_pd_num, $connection) or die(mysql_error());
				$row_pd_num = mysql_fetch_assoc($pd_num);
				$totalRows_pd_num = mysql_num_rows($pd_num);
			    do { $d[] = $row_pd_num['del_num']; } while ($row_pd_num = mysql_fetch_assoc($pd_num));
				sort($d);
				foreach (array_unique($d) as $value1) {
						$query_pd_loop = sprintf("SELECT * FROM project_deliverable WHERE cid='%s' AND mid='%s' AND del_num='%s' ORDER BY vid DESC LIMIT 1", $cid, $value, $value1);
						$pd_loop = mysql_query($query_pd_loop, $connection) or die(mysql_error());
						$row_pd_loop = mysql_fetch_assoc($pd_loop);
						$totalRows_pd_loop = mysql_num_rows($pd_loop);
						
						$query_pd_los = sprintf("SELECT * FROM learning_outcomes WHERE cid='%s' AND del_num='%s'", $cid, $row_pd_loop['del_num']);
						$pd_los = mysql_query($query_pd_los, $connection) or die(mysql_error());
						$row_pd_los = mysql_fetch_assoc($pd_los);
						$totalRows_pd_los = mysql_num_rows($pd_los);
						
						$query_pd_comments = sprintf("SELECT * FROM comments WHERE cid='%s' AND tableName='project_deliverable' AND rid='%s'", $cid, $row_pd_loop['id']);
						$pd_comments = mysql_query($query_pd_comments, $connection) or die(mysql_error());
						$row_pd_comments = mysql_fetch_assoc($pd_comments);
						$totalRows_pd_comments = mysql_num_rows($pd_comments);
						
						if ($totalRows_pd_loop > 0) {
							echo "<tr style='background-color: ".$color."'>\n";
							echo "<td>Module ".$row_pd_loop['mid']."</td>\n";
							echo "<td class='data'>";
							if (!strstr($section, "step")) {
							if ($row_user['userLevel'] <= "2") echo "<div class='stacked'><span class='icon'><img src='images/page_edit.png' border='0' align='absmiddle' /></span><a id='modal_window_link' href='index.php?section=proj_deliv&action=edit&go=".$go."&amp;view=proposal_detail&cid=".$cid."&vid=".$row_pd_loop['vid']."&id=".$row_pd_loop['id']."&amp;modal_window=true'>Edit</a></div>";
							echo "<div class='stacked'><a id='modal_window_link' href='index.php?section=view_proposal&amp;action=".$action."&amp;dbTable=project_deliverable&amp;cid=".$cid."&id=".$row_pd_loop['id']."&amp;modal_window=true'>Deliverable ".$row_pd_loop['del_num'].": ".$row_pd_loop['pd_name']."</a></div>";
							}
							else echo "Deliverable ".$row_pd_loop['del_num'].": ".$row_pd_loop['pd_name'];
							echo "</td>\n";
							if ((!strstr($section, "step")) && ($modal_window != "true")) { 
								echo "<td class='data'>";
								  if ($totalRows_pd_los > 0) echo "<div class='stacked'><span class='icon'><img src='images/tick.png' align='absmiddle' border='0'></span><a id='modal_window_link' href='index.php?section=view_proposal&dbTable=project_deliverable&cid=".$cid."&id=".$row_pd_loop['id']."&amp;modal_window=true' title='View Associated Learning Outcomes'>Yes</a></div>"; else echo "<div class='stacked'><span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>No</div><div class='stacked'><span class='icon'><img src='images/page_add.png' align='absmiddle' border='0'></span><a id='modal_window_link' href='index.php?section=clo&action=add&go=overview&cid=".$cid."&mid=".$row_pd_loop['mid']."&del_num=".$row_pd_loop['del_num']."&amp;modal_window=true'>Add CLO?</a>";
								echo "</td>";
								echo "<td class='data'>";
								if ($totalRows_pd_comments > 0) echo "<div class='stacked'><span class='icon'><img src='images/comment.png' align='absmiddle' border='0'></span>Yes - <a id='modal_window_link' href='index.php?section=view_comments&amp;dbTable=project_deliverable&amp;cid=".$cid."&amp;id=".$row_pd_loop['id']."&amp;modal_window=true' title='View ID Comments'>View</a></div>"; else echo "<div class='stacked'><span class='icon'><img src='images/comment_fade.png' align='absmiddle' border='0'></span>No</div>"; if ($row_user['userLevel'] <= "2") echo "<div class='stacked'><span class='icon'><img src='images/comment_add.png' align='absmiddle' border='0'></span><a id='modal_window_link' href='index.php?section=comments&action=add&amp;cid=".$cid."&amp;dbTable=project_deliverable&amp;id=".$row_pd_loop['id']."&amp;modal_window=true'>Add Comment</a></div>";
								echo "</td>";
								echo "<td class='data'>";
								if ($row_pd_comments['changes'] == "Y") { echo "<div class='stacked'><span class='icon'><img src='images/error.png' align='absmiddle' border='0'></span>Yes"; if ($row_user['userLevel'] == "3") echo " - <a id='modal_window_link' href='index.php?section=proj_deliv&amp;action=add&amp;go=".$go."&amp;view=proposal_detail&amp;dbTable=project_deliverable&amp;cid=".$cid."&amp;id=".$row_pd_loop['id']."&amp;modal_window=true' title='Make Changes'>Make Changes</a>"; echo '</div>'; } else echo "<div class='stacked'><span class='icon'><img src='images/tick.png' align='absmiddle' border='0'></span>No</div>";
								echo "</td>";
							}
							if ($row_user['userLevel'] <= "2") { 
							if ($section == "view_proposal") { 
								echo "<td class='data'><a id='modal_window_link' href='index.php?section=view_proposal&amp;dbTable=project_deliverable&amp;cid=".$cid."&amp;id=".$row_pd_loop['id']."&amp;modal_window=true'>".$row_pd_loop['vid']."</a></td>\n";
								
							echo "<td class='data'>";
								$query_pd_num = sprintf("SELECT * FROM project_deliverable WHERE cid='%s' AND mid='%s' AND del_num='%s' ORDER BY vid", $cid, $value, $value1);
								$pd_num = mysql_query($query_pd_num, $connection) or die(mysql_error());
								$row_pd_num = mysql_fetch_assoc($pd_num);
								$totalRows_pd_num = mysql_num_rows($pd_num);
								if ($totalRows_pd_num > 1) { 
									do 	{ 
										if (($totalRows_pd_num > 0) && ($row_pd_num['vid'] != $row_pd_loop['vid'])) echo "<a id='modal_window_link' href='index.php?section=view_proposal&amp;dbTable=project_deliverable&amp;cid=".$cid."&amp;id=".$row_pd_num['id']."&amp;modal_window=true'>".$row_pd_num['vid']."</a>&nbsp;&nbsp;"; 
										} while ($row_pd_num = mysql_fetch_assoc($pd_num));
								} else echo "None";
							echo "</td>\n";
							}
							}
							if ($section == "proposal_reveiw") echo "<td class='data'><a href='index.php?section=proj_deliv&action=edit&go=review&cid=".$cid."&vid=".$row_pd_loop['vid']."&id=".$row_pd_loop['id']."'>Yes</a></td>";
							echo "</tr>\n";
							if ($color == $color1) { $color = $color2; } else { $color = $color1; }
							}
						}
				}
		}
if ($section == "proposal_titles") { 
$query_pd_num = sprintf("SELECT * FROM project_deliverable WHERE cid='%s' AND mid='%s' ORDER BY vid ", $cid, $mid);
$pd_num = mysql_query($query_pd_num, $connection) or die(mysql_error());
$row_pd_num = mysql_fetch_assoc($pd_num);
$totalRows_pd_num = mysql_num_rows($pd_num);
if ($totalRows_pd_num > 0) { ?>
	<table class='dataTable'>
  		<tr>
    		<th width="15%" nowrap="nowrap">Applies To</th>
    		<th>Course Project Deliverable</th>
  		</tr>
<?php 
do { $d[] = $row_pd_num['del_num']; } while ($row_pd_num = mysql_fetch_assoc($pd_num));
	sort($d);
	foreach (array_unique($d) as $value1) {
	$query_pd_loop = sprintf("SELECT * FROM project_deliverable WHERE cid='%s' AND mid='%s' AND del_num='%s' ORDER BY vid DESC LIMIT 1", $cid, $mid, $value1);
	$pd_loop = mysql_query($query_pd_loop, $connection) or die(mysql_error());
	$row_pd_loop = mysql_fetch_assoc($pd_loop);
	$totalRows_pd_loop = mysql_num_rows($pd_loop);
		if ($totalRows_pd_loop > 0) { ?>
		<tr style="background-color: <?php echo $color; ?>">
			<td>Module <?php echo $row_pd_loop['mid']; ?></td>
			<td class="data">Deliverable <?php echo $row_pd_loop['del_num']. ": ".$row_pd_loop['pd_name']; ?></td>
		</tr>
        <?php } 
		 }   
	} else echo "<div class='error_msg'>There are no project deliverables associated with this module.</div>";
}
echo "</table>";
echo top_link($section,$modal_window);  ?>
